package com.gaogzhen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaogzhen.domain.UserAddress;
import com.gaogzhen.service.UserAddressService;
import com.gaogzhen.utils.CurrentUser;
import com.gaogzhen.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author Administrator
 * @version 1.0
 * @description 会员地址管理器
 * @date 2022-06-08 11:35
 */
@RestController
@RequestMapping("/userAddress")
@Api(tags = "会员地址管理器")
public class UserAddressController {

    @Autowired
    UserAddressService userAddressService;

    @GetMapping
    @ApiOperation("分页查询会员地址列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "size", value = "每页大小"),
            @ApiImplicitParam(name = "userId", value = "会员id")
    })
    @PreAuthorize("hasAuthority('user_address_query')")
    public R<Page<UserAddress>> findByPage(@ApiIgnore Page<UserAddress> page, Long userId) {
        return R.ok(userAddressService.findByPage(page, userId));

    }

    @GetMapping("/getCoinAddress/{coinId}")
    @ApiOperation("查询充币地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "coinId", value = "币种id")
    })
    public R<String> getCoinAddress(@PathVariable("coinId") Long coinId) {
        UserAddress coinAddress = userAddressService.getCoinAddress(CurrentUser.getCurrentUserId(), coinId);
        return R.ok(coinAddress.getAddress());
    }
}
